package com.sixth.statistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sixth.core.entity.CareOrderItem;
import com.sixth.core.vo.R;
import com.sixth.statistics.mapper.CareOrderItemMapper;
import com.sixth.statistics.service.CareOrderItemService;
import com.sixth.statistics.vo.CareOrderItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @program: six-hospital-system
 * @description:
 * @author: 朱永奇
 * @create: 2024-08-17 17:29
 **/
@Service
public class CareOrderItemImpl extends ServiceImpl<CareOrderItemMapper, CareOrderItem> implements CareOrderItemService {
    @Autowired
    private CareOrderItemMapper careOrderItemMapper;
    /**
     * 药品销售分页统计
     * @param careOrderItemVo
     * @return
     */
    @Override
    public R<IPage<CareOrderItem>> selectByPage(CareOrderItemVo careOrderItemVo) {
        // 创建分页对象
        IPage<CareOrderItem> page = new Page<>(careOrderItemVo.getPageNum(),careOrderItemVo.getPageSize());
        // 创建查询条件
        QueryWrapper<CareOrderItem> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(careOrderItemVo.getItemName())) {
            wrapper.like("item_name", careOrderItemVo.getItemName());
        }
        if (careOrderItemVo.getDateRange() != null && careOrderItemVo.getDateRange().size() == 2) {
            wrapper.between("create_time", careOrderItemVo.getDateRange().get(0), careOrderItemVo.getDateRange().get(1));
        }
        // 固定条件
        wrapper.eq("item_type", 0);
        wrapper.ne("status", 2).ne("status", 5).ne("status", 0);
        // 执行分页查询
        IPage<CareOrderItem> careOrderItemIPage = careOrderItemMapper.selectPage(page, wrapper);
        // 返回结果
        return R.ok(careOrderItemIPage);
    }
    /**
     * 药品总数统计
     * @param careOrderItemVo
     * @return
     */
    @Override
    public R<List<CareOrderItem>> selectCare(CareOrderItemVo careOrderItemVo) {
        List<CareOrderItem> c = careOrderItemMapper.selectListCare(careOrderItemVo);
        return R.ok(c);
    }
    /**
     * 检查总数统计
     * @param careOrderItemVo
     * @return
     */
    @Override
    public R<List<CareOrderItem>> selectCareOrder(CareOrderItemVo careOrderItemVo) {
        List<CareOrderItem> careOrderItems = careOrderItemMapper.selectListCareOrder(careOrderItemVo);
        return R.ok(careOrderItems);
    }
}
